<?php if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=""){?>
<div class="col-md-8">
<div class="main-content" id="main-content">
	<div class="sub-content">	
			<div class="top-header page-header clearfix">
				<h1>Change Password</h1>
			</div>
			<div class="middle-forms user-profile1">
			<form  class="form-horizontal" role="form">
				<div class="sub-forms">
				   <div class="form-group">
						<label class="control-label col-sm-3">Old Password</label>
						<div class="col-sm-9">
						<input class="input_type_text form-control" type="password" name="oldpwd" id="oldpwd" placeholder="Your old password"/></div>
					</div>
					<div class="form-group">
						<label class="control-label col-sm-3">New Password</label>
						<div class="col-sm-9">
						<input class="input_type_text form-control" type="password" name="newpwd" id="newpwd"  placeholder="Your new password"/></div>
					</div>
					<div class="form-group">
						<label class="control-label col-sm-3">Confirm Password</label>
						<div class="col-sm-9">
						<input class="input_type_text form-control" type="password" name="confirm-pwd" id="confirm-pwd"  placeholder="Your confirm password"/></div>
					</div>
					<div class="adding_list form-group">
						<label class="col-sm-3">&nbsp;</label>
							
								<a href="javascript:void(0)" onclick="return changePassword();" role="button" class="btn btn-danger">Submit</a>
							
						
					</div>	
					<span id="confirmerrormsg1" style="margin-left:70px;color:red"><span>			
					<span id="confirmerrormsg" style="margin-left:70px;color:green"><span>
					<input type="hidden" id="hid_user_id" name="hid_user_id" value="<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=""){ echo $_SESSION['user']['user_id'];}?>">
				</div>
				</form>
			</div>
	</div>
</div>
</div>
<!--End-->
<script>
	function changePassword(){	
		var flag=true;
		var userId='<? echo $_SESSION['user']['user_id']?>';
		var oldpasswrd=$("#oldpwd").val();		
		var passwrd=$("#newpwd").val();
		var cnfpwrd=$("#confirm-pwd").val();		
		if(passwrd==""&& cnfpwrd==""){
			$("#confirmerrormsg1").html('Your new password is required');
			flag=false;
			$("#newpwd").focus();
		}
		if(oldpasswrd==""){
			$("#confirmerrormsg1").html('Your old password is required');
			flag=false;
			$("#oldpwd").focus();
		}	
		if(flag==false){ 
				return false;
		}else{			
			if(passwrd==cnfpwrd){
				$.ajax({
					type:'POST',
					url: BASE_PATH+'/users/checkPassword',
					data:{oldpasswrd:oldpasswrd,userId:userId},
					success: function(data){
						if(data.output=='success'){	
							$.ajax({
								type:'POST',
								url: BASE_PATH+'/users/change-password',
								data:{cnfpwrd:cnfpwrd,userId:userId},
								success: function(data){
									$("#confirmerrormsg").html('Your password successfully updated');
									window.location='<? echo $this->Url('home')?>';
								}
							});					
						}else{
							$("#confirmerrormsg1").html('You entered old password is wrong');
						}
					}
				});					
			}else{
				$("#confirmerrormsg1").html('Your confirm password do not match');
				$("#confirm-pwd").focus();
			}
		}		
	}	
</script>
<?php } else {?>
	<script>
		window.location='<? echo $this->Url('home')?>';
	</script>
<?}?>